
package system.base;

import framework.core.*;
import system.SelectManager;
import system.data.*;

/*
	Author    :chengbiao.he
	CreateTime:2008-02-28 10:58:26
*/
public class WarehouseCategoryRelation extends WarehouseCategoryRelationBase 
{

//----system generated start----// 	
public WarehouseCategoryRelation() 
{
	
}

public static void delete(DBConnection con,String id) throws Exception
{
	Conditions conditions = new Conditions();

	conditions.add(ID,id);
	
	delete(con,TABLE_NAME,conditions);
}
public static WarehouseCategoryRelation fetch()
{
	return new WarehouseCategoryRelation();
}
public static WarehouseCategoryRelation copy(WarehouseCategoryRelation srcObj)
{
	WarehouseCategoryRelation obj = fetch();
	obj.copyBase(srcObj);
	return obj;
}
public static WarehouseCategoryRelation fetch(DBConnection con,String id) throws Exception
{
	Conditions conditions = new Conditions();

	conditions.add(ID,id);
	
	return fetch(con,conditions);
}

public static WarehouseCategoryRelation fetchByProductCode(DBConnection con,String productCode) throws Exception
{
	Conditions conditions = new Conditions();

	conditions.add(PRODUCT_CODE,productCode);
	
	return fetch(con,conditions);
}

public static WarehouseCategoryRelation fetch(DBConnection con,Conditions conditions) throws Exception
{
	DBResult result = null;
	try
	{
		result = DBEngine.doSelect(con,"select * from " + TABLE_NAME,conditions);
		java.sql.ResultSet rs = result.getRs();
		WarehouseCategoryRelation obj = null;
		if(rs.next())
		{
			obj = fetch(rs);
		}
		return obj;
	}
	finally
	{
		if(result!=null) result.clear() ;
	}
}
public static WarehouseCategoryRelation fetch(java.sql.ResultSet rs) throws Exception
{
	WarehouseCategoryRelation obj = new WarehouseCategoryRelation();
	obj.initObject(rs);
	return obj;
}
protected void getUnique(DBConnection con) throws Exception
{
		setId(DBEngine.getId(con));
}
//----system generated end----//



//----add by chengbiao.he start----//


//----add by chengbiao.he end----//

// add by Sindy start
public static WarehouseCategoryRelation fetchGetDisplayOrder(DBConnection con) throws Exception
{
    DBResult result = null;
    try
    {
        result = DBEngine.doSelect(con,"select * from " + TABLE_NAME +" order by " + DISPLAY_ORDER + " desc");
        java.sql.ResultSet rs = result.getRs();
        WarehouseCategoryRelation obj = null;
        if(rs==null){
            obj = null;
        }else{
            if(rs.next())
            {
                obj = fetch(rs);
            }
        }
        return obj;
    }
    finally
    {
        if(result!=null) result.clear() ;
    }
}

//重写仓库名称
public String viewWarehouseName(DBConnection con) throws Exception
{
    String mReturn = "";
    Warehouse w = Warehouse.fetchByCode(con, getWarehouseCode());
    if (w != null)
    {
        mReturn = w.getName();
    }
    return mReturn;
}

public static WarehouseCategoryRelation fetchbyProductWarehouseCode(DBConnection con,String productCode,String warehouseCode) throws Exception
{
    WarehouseCategoryRelation wcr = null;
    Conditions conditions = new Conditions();

    conditions.add(PRODUCT_CODE,productCode);
    if(!warehouseCode.equals("000000"))
        conditions.add("substr("+WAREHOUSE_CODE+",1,4)",warehouseCode.substring(0, 4));

    wcr = fetch(con,conditions);
    if (wcr == null)
        return null;
    else
        return wcr;
}
// add by Sindy end
 
}

